#include <stdio.h>
#include <stddef.h>

#define container_of(ptr, type, member) ({		\
			const typeof( ((type*)0)->member) *__mptr = (ptr);	\
			(type *)((char *)__mptr - offsetof(type, member) );})
			
struct test {
	int x;
	int y;
};

int main()
{
	struct test t = { .x = 10, .y = 20 };
	
	printf("&t		= %p\n", &t);		// 0xbf916a90
	printf("&t.x		= %p\n", &t.x);	// 0xbf916a90
	printf("&t.y		= %p\n", &t.y);	// 0xbf916a94

	printf("offsetof(struct test, x)		= %d\n", offsetof(struct test, x));	// 0
	printf("offsetof(struct test, y)		= %d\n", offsetof(struct test, y));	// 4

	printf("start position : = %p\n", container_of(&t.x, struct test, x));	// 0xbf916a90
	printf("start position : = %p\n", container_of(&t.y, struct test, y));	// 0xbf916a90
	
	return 0;
}

